local love = require "love"
local Button = {}

function Button.new(self, x, y, text, func, func_param, width, height)
    local object = {}
    self.__index = self
    setmetatable(object, self)

    object.x = x or 10
    object.y = y or 10
    object.text = text or "No text"
    object.func = func
    object.func_param = func_param
    object.width = width or 40
    object.height = height or 20

    return object
end

function Button.draw(self)
    love.graphics.setColor(0.6, 0.6, 0.6)
    love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)

    love.graphics.setColor(0, 0, 0)
    love.graphics.print(self.text, self.x + 1 / 4 * self.width, self.y + 1 / 4 * self.height)
end

function Button.click(self, mouse_x, mouse_y)
    if mouse_x > self.x and mouse_x < self.x + self.width and
        mouse_y > self.y and mouse_y < self.y + self.height then
        if self.func_param then
            self.func(self.func_param)
        else
            self.func()
        end
    end
end

return Button
